#include<cstdio>
#include<cstring>
#include<algorithm>

char a[7];

int main()
{
	//freopen("in","r",stdin);
	int s_1=1,s_2=1;
	scanf("%s",a);
	int len = strlen(a);
	for(int i=0;i<=len;i++)
	{
		s_1 *= ( (int)a[i] - 'A' + 1);
	}
	scanf("%s",a);
	len = strlen(a);
	for(int i=0;i<=len;i++)
	{
		s_2 *= ( (int)a[i] - 'A' + 1);
	}
	if(s_1%47 == s_2%47)
		printf("GO");
	else
		printf("STAY");
	//fclose(stdin);
	return 0;
}
